package com.sdy.service.Impl;

import com.sdy.dao.mysql.CompanyMapper;
import com.sdy.dao.mysql.NoticMapper;
import com.sdy.dao.mysql.UserMapper;
import com.sdy.po.Notic;
import com.sdy.po.User;
import com.sdy.service.NoticService;
import com.sdy.util.Contact;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class NoticServiceImpl implements NoticService {

    @Resource
    NoticMapper noticMapper;
    @Resource
    UserMapper userMapper;

    @Override
    public void insertNotic(Notic notic) {

    }

    @Override
    public void markAsRead(Integer noticId) {
        noticMapper.markAsRead(noticId, Contact.NOTIC_READSTATE_READ);
    }

    @Override
    public Notic getOneById(Integer noticId) {
        return noticMapper.getOneById(noticId);
    }



    @Override
    public List<Notic> getListByCompanyId(Integer companyId) {
        return noticMapper.getListByCompanyId(companyId);
    }

    @Override
    public List<Notic> getAll() {
        return noticMapper.getAll();
    }



    @Override
    public Boolean sendNotic(Notic notic, String authority) {

        List<User> receiveUserList = null;

        if (authority.equals(Contact.AUTHERITY_All)){
            receiveUserList = userMapper.ListAllNameAndCompanyId();
        }
        else if (authority.equals(Contact.AUTHERITY_CUSTOMER)){
            receiveUserList = userMapper.ListCustomerNameAndCompanyId();
        }
        else if (authority.equals(Contact.AUTHERITY_MANAGER)){
            receiveUserList = userMapper.ListManagerNameAndCompanyId();
        }

        return noticMapper.batchInsert(notic,receiveUserList);
    }

    private void sendNoticToAll(){

    }

//    public void insertNotic(String dataState, Integer companyId, Parm parm, JSONObject data){
//        noticMapper.insertNotic(noticUtil.dataToNotic(dataState,companyId,parm,data));
//    }
}
